package main

import (
	"fmt"
	"net/http"
)

func main() {
	http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		//fmt.Fprintf(writer, "hello world from go web server. Your url: %s", request.URL.Path)
		parserHttpRequest(writer, request)
	})
	http.ListenAndServe(":8989", nil)
}

func parserHttpRequest(writer http.ResponseWriter, request *http.Request) {

	fmt.Fprintf(writer, "Requeset URL: %s \n", request.URL.String())
	fmt.Fprintf(writer, "Requeset Method: %s\n", request.Method)
	fmt.Fprintf(writer, "Remote address: %s\n", request.RemoteAddr)
	fmt.Fprintf(writer, "HTTP Version: %s\n", request.Proto)
	fmt.Fprint(writer, "Headers:\n")
	for k, vs := range request.Header {
		s := ""
		for _, v := range vs {
			s += v
		}
		fmt.Fprintf(writer, "%s : %s \n", k, s)
	}

	//	Request URL:https://translate.google.cn/gen204?ilog=orig&client=webapp&cpy=0&clk=1&sel=0&ctx=0
	//Request method:GET
	//Remote address:203.208.40.95:443
	//Status code:
	//Version:HTTP/2
	//Referrer Policy:no-referrer-when-downgrade
	//Header
	//Body
}
